<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category ArticleStockController.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/7/10  16:40
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Services\StockArticleService;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;

//废弃
class ArticleStockController extends Controller
{
    /**
     * @return Factory|View
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:48
     */
    public function index(Request $request){
        $compact = compact('request');

        return view('admin.article_stock.index',$compact);
    }

    /**
     * @param Request $request
     * @return array
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:48
     */
    public function getList(Request $request){

        $list = StockArticleService::getInstance()->getList($request);

        return ['code' => 0, 'data'=>$list];
    }

    /**
     * @param Request $request
     * @return Factory|View
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:48
     */
    public function create(Request $request){
        $category   = Category::getCateLevel();
        $compact    = compact('request','category');

        return view('admin.article.create',$compact);
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:49
     */
    public function store(Request $request){
        $responseData = Article::addData($request);

        return response()->json($responseData);

    }

    /**
     * @param Request $request
     * @param $id
     * @return Factory|View
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:49
     */
    public function edit(Request $request, $id){
        $data     = Article::getOne($id);
        $category = Category::getCateLevel();
        $compact  = compact('request','data', 'category');

        return view('admin.article.edit',$compact);
    }

    /**
     * @param Request $request
     * @param $id
     * @return JsonResponse
     * @Depiction
     * @Author hwy
     * @Date  2020/4/27  14:49
     */
    public function update(Request $request,$id){
        $responseData = Article::editData($request,$id);

        return response()->json($responseData);
    }

}
